<?php
require_once 'XPHP/Controller/Interface.php';
/**
 * Lớp abstract của Controller
 * @author Mr.UBKey
 * @package XPHP
 * @version Beta
 * @copyright XWEB
 */
abstract class XPHP_Controller_Abstract implements XPHP_Controller_Interface
{
	/**
	 * Router của hệ thống
	 * @var XPHP_Router
	 */
	protected $_router;
	
	public function __construct()
	{
		//Router
		$this->_router = new XPHP_Router();
		//Include Path
		$this->setIncludePath();
		//Analysis Request Uri
		$this->_router->analysisRequestUri();
	}
	
	/**
	 * Gán router vào controller
	 * @param XPHP_Router $router
	 */
	public function setRouter($router)
	{
		$this->_router = $router;
	}
	
	/**
	 * Gán include path
	 */
	public function setIncludePath()
	{
		//Include đường dẫn tới Application
		set_include_path(get_include_path() . PATH_SEPARATOR . $this->_router->getApplicationDir());
		//Inlude đường dẫn tới Application Controller
		$controllerPath = $this->_router->getApplicationDir() . 
						  '/' . $this->_router->getControllerDir(); 
		set_include_path(get_include_path() . PATH_SEPARATOR . $controllerPath);
		//Include đường dẫn tới thư mục Area 
		set_include_path(get_include_path() . PATH_SEPARATOR . $this->_router->getAreaDir());
		//Inlude đường dẫn tới Area Controller
		foreach ($this->_router->getAreas() as $path)
		{
			$areaControllerPath = $path . '/' . $this->_router->getControllerDir();
			set_include_path(get_include_path() . PATH_SEPARATOR . $areaControllerPath);
		}
	}
} 